package personal.learn.whiteboard;

import java.util.Scanner;

public class Main {
    // HG[3|B[2|CA]]F
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        while(s.contains("[")){
            s = dealWithCompressionString(s);
        }
        System.out.println(s);
    }

    public static String dealWithCompressionString(String s) {
        char[] chars = s.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '[') {
                // 拿到次数
                int times = chars[i + 1] - 48;
                // 拿到中括号内的字符串
                StringBuilder sb2 = new StringBuilder();
                // i+2 是 |
                int begin = i + 3;
                int outflag = 0;
                for (int m = begin; ; m++) {
                    // 若中间的字符串递归结束，且遇到了右括号，退出
                    if (outflag == 0 && chars[m] == ']') {
                        i = m;
                        break;
                    }
                    if (chars[m] == '[') {
                        outflag++;
                    }
                    if (chars[m] == ']') {
                        outflag--;
                    }
                    sb2.append(chars[m]);
                }
                for (int j = 0; j < times; j++) {
                    sb.append(sb2.toString());
                }
            } else {
                sb.append(chars[i]);
            }
        }
        return sb.toString();
    }

}
